﻿@model SweetSurvey.Models.ViewModels.ResultsViewModel

@foreach (var r in Model)
{
    var maxVal = r.Values.Max(); // total answers of the most popular option in this question
    var sumVal = r.Values.Sum(); // total answers of all options in this question
    
    <div class="report-question-title">@r.Title</div>
    <table cellspacing="6" class="report-question-options">
        @for (var i = 0; i < r.Options.Count; i++)
        {
            var option = r.Options[i]; // option text
            var value = r.Values[i];   // total answers of this option
            var widthPercentage = maxVal > 0 ? Math.Round((double)(value * 100) / maxVal) : 0; // width
            var valuePercentage = sumVal > 0 ? Math.Round((double)(value * 100) / sumVal) : 0; // value
            <tr>
                <td class="text">@option</td>
                <td class="bar"><div style="width:@widthPercentage%"></div></td>
                <td class="value">@value (@valuePercentage%)</td>
            </tr>
        }
    </table>
}